package com.help10000.rms.ui.adapter

import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.view.View
import com.amir.common.beans.OrderItem
import com.amir.common.holder.CommonViewHolder
import com.amir.common.mvp.base.BaseRecyclerAdapter
import com.amir.common.utils.DialoghintUtils
import com.amir.common.utils.DialoghintUtils.ButtonOnClickListener
import com.help10000.rms.R
import com.help10000.rms.ui.activitys.CashEntryActivity
import com.help10000.rms.ui.activitys.MapNavigationActivity
import com.help10000.rms.ui.activitys.PickingMaterialActivity
import com.help10000.rms.ui.activitys.ReportOrderActivity

class ServiceHisAdapter(context: Context?, dataList: List<OrderItem?>?, layoutId: Int) :
    BaseRecyclerAdapter<OrderItem?>(context, dataList, layoutId) {


    override fun bindData(holder: CommonViewHolder?, data: OrderItem?, position: Int) {

        val repairInfo = data?.RepairInfo
        //拒绝
        holder?.setViewVisibility(R.id.tv_refuse,  View.GONE)
        //接单
        holder?.setViewVisibility(R.id.tv_roborder, View.GONE)
        //完工上报
        holder?.setViewVisibility(R.id.tv_report, View.GONE)
        //收款
        holder?.setViewVisibility(R.id.tv_gathering, View.GONE)
        //领料
        holder?.setViewVisibility(R.id.tv_lingliao, View.GONE)

//        holder?.setText(R.id.tv_date, text = "${repairInfo?.AppointmentTime}")
//        holder?.setText(R.id.tv_num, text = "${position + 1}")
//        holder?.setText(R.id.tv_price, text = "${repairInfo?.VirtCharge}")
//        holder?.setText(R.id.tv_orderno, text = "${repairInfo?.RepairId}")
//        holder?.setText(R.id.tv_nameTel, text = "${repairInfo?.CustName}  ${repairInfo?.Tel}")
//        holder?.setText(
//            R.id.tv_address,
//            text = " ${repairInfo?.ProvName}${repairInfo?.CityName}${repairInfo?.TownName}${repairInfo?.Zone5}"
//        )
//        holder?.setText(R.id.tv_companyname, text = "${repairInfo?.CmpyName}")
//        holder?.setText(R.id.tv_status, text = "${repairInfo?.Status}")
//        holder?.setText(R.id.tv_desc, text = "${repairInfo?.CallDescr}")
//        holder?.setOnClickListener(R.id.tv_refuse) { v: View? ->  //拒绝订单
//            val intent = Intent(mContext, RefuseOrderActivity::class.java)
//            intent.putExtra("data", repairInfo)
//            mContext.startActivity(intent)
//        }
        holder?.setOnClickListener(R.id.tv_report) { v: View? ->  //完工上报
            val intent = Intent(mContext, ReportOrderActivity::class.java)
            intent.putExtra("data", repairInfo)
            mContext.startActivity(intent)
        }
        holder?.setOnClickListener(R.id.tv_lingliao) { v: View? ->  //领料
            val intent = Intent(mContext, PickingMaterialActivity::class.java)
            intent.putExtra("data", repairInfo)
            mContext.startActivity(intent)
        }
        holder?.setOnClickListener(R.id.tv_gathering) { v: View? ->//收款
            val intent = Intent(mContext, CashEntryActivity::class.java)
            intent.putExtra("data", repairInfo)
            mContext.startActivity(intent)
        }
        holder?.setOnClickListener(R.id.tv_address) {//导航
            val intent = Intent(mContext, MapNavigationActivity::class.java)
            intent.putExtra("data", repairInfo)
            mContext.startActivity(intent)
        }
        holder?.setOnClickListener(R.id.tv_nameTel) {
//            if (repairInfo?.Tel != null) {
//                PhoneUtils.callPhone(mContext, repairInfo.Tel)
//            }

        }

        holder?.setOnClickListener(R.id.tv_roborder) { v: View? ->
            val show = DialoghintUtils()
                .init(mContext)

                .setContent("确定抢单？")
                .setAff(R.string.aff)
                .setClose(R.string.close)
                .setOnclick(object : ButtonOnClickListener {
                    override fun close(alertDialog: AlertDialog) {}
                    override fun aff(alertDialog: AlertDialog) {}
                }).show()
        }
        holder?.setOnClickListener(R.id.ll_root) {
//            val intent = Intent(mContext, OrderDetailsActivity::class.java)
//            intent.putExtra("RepairId", repairInfo?.RepairId)
//            mContext.startActivity(intent)
        }
    }
}